"""
@author: Sergiy Tsymbalyuk
"""

from pylons.i18n import lazy_ugettext as _

from sqlalchemy import Column, ForeignKey
from sqlalchemy.types import Integer, String, Date, Enum, Boolean
from sqlalchemy.orm import relation

from chowa.model.meta import Base

__all__ = ['Country', 'LocalityType', 'Locality']


class Country(Base):
    __tablename__ = 'geo_country'
    
    id = Column(Integer, primary_key=True)
    name = Column(String(255), info={'verbose': _('Object|Name')})
    
    def __unicode__(self):
        return self.name
    

class LocalityType(Base):
    __tablename__ = 'geo_locality_type'
    
    id = Column(Integer, primary_key=True)
    name = Column(String(100), info={'verbose': _('Object|Name')})
    abbreviation = Column(String(10), info={'verbose': _('Abbreviation')})
    
    def __unicode__(self):
        return self.name


class Locality(Base):
    __tablename__ = 'geo_locality'
    
    id = Column(Integer, primary_key=True)
    name = Column(String(255), info={'verbose': _('Object|Name')})
    country_id = Column(Integer, ForeignKey(Country.id), info={'verbose': _('Country')})
    type_id = Column(Integer, ForeignKey(LocalityType.id), info={'verbose': _('Type')})
    
    country = relation(Country)
    type = relation(LocalityType)
    
    def __unicode__(self):
        return self.name
